import { message } from 'antd';
import api from '../../api';
export default {
  namespace: 'rollOverM',
  state: {},

  effects: {
    //债券转仓
    *rollOver0({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.bondRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //基金转仓
    *rollOver1({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.fundRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //回购转仓
    *rollOver2({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.buybackRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //理财直融转仓
    *rollOver3({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.finaFlockingRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //存款转仓
    *rollOver4({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.DepositRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //非标转仓
    *rollOver5({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.nonstandardRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },

    //股票转仓
    *rollOver6({ payload, callback }, { call, put }) {
      const response = yield call(api.rollOver.stockRollOver, payload);
      if (response && response.code == 0) {
        callback(true);
      } else {
        callback();
        message.error(response.message || '转仓失败!');
      }
    },
  },
  reducers: {
    save(state, { payload }) {
      return { ...state, ...payload };
    },
  },
};
